package com.nage.multiplayer;

public class SyncThread extends Thread {

	private static final long SYNC_WAIT = 500;
	MultiplayerSystem m_MultiplayerSystem;
	private long current;
	private long last;
	private boolean running;
	
	public SyncThread(MultiplayerSystem m) {
		m_MultiplayerSystem = m;
	}
	
	@Override
	public void run() {
		running = true;
		while(running) {
			current = System.currentTimeMillis();
			if(current - last > SYNC_WAIT) {
				m_MultiplayerSystem.performSync();
				last = current;
			} else {
				try {
					sleep(SYNC_WAIT - (current - last));			
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}

	public void onPause() {
		running = false;
	}

}
